<?php
require_once '../app/core/models/BaseDao.php';
require_once '../app/core/db/DBUtil.class.php';

class CampusDao extends BaseDao {
	
	private $tableName = "agent_campuses";
	
	public function save($campus){
		$campus[1] = str_replace('"','',$campus[1]);
		$campus[1] = iconv('gb2312','utf-8',trim($campus[1]));
		$campus[2] = str_replace('"','',$campus[2]);
		$campus[2] = iconv('gb2312','utf-8',trim($campus[2]));
		
		$param = array($campus[0], $campus[1],$campus[2],$campus[3],$campus[5]);
//		print_r($param);die;
        $sql = "insert into $this->tableName (id, area_name, comment,visible,area_dict_id, is_delete, modified, created) values (?,?,?,?,?,0,now(),now())";
        return $this->dbUtil->ExecuteQuery($sql, $param);
	}
	
	public function getCampusByDictId($areaDictId,$showInOrder){
        $params = array($areaDictId);
        if($showInOrder == 1){
        	$sql = "select * from $this->tableName where area_dict_id = ? and visible = 1 and show_in_order = 1 and is_delete = 0 ";
        }else{
        	$sql = "select * from $this->tableName where area_dict_id = ? and visible = 1 and is_delete = 0 ";
        }       
        return $this->dbUtil->SelectData($sql, $params);		
	}
	
	public function getCampusById($id){
        $params = array($id);
        $sql = "select * from $this->tableName where id = ? and visible = 1 and is_delete = 0 ";
        return $this->dbUtil->SelectData($sql, $params);		
	}
	
}
